package com.yanqu.road.server.cmd;

import com.yanqu.road.connect.AgentServerLinkControl;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.player.Player;
import com.yanqu.road.player.PlayerControl;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.AgentProtocol;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.HashMap;
import java.util.Map;

@Cmd(code = AgentProtocol.A_STRONGHOLD_MAMMON_HELP_NOTICE,desc = "据点战财神助力广播")
public class StrongholdMammnoNoticeCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        Map<Long, Player> allPlayer = new HashMap<>(PlayerControl.getOnlinePlayerMap());
        for (Map.Entry<Long, Player> dataEntry : allPlayer.entrySet()) {
            YanQuMessage msg = YanQuMessageUtils.buildMessageByte(Protocol.U_STRONGHOLD_MAMMON_HELP_NOTICE, packet.getBytes());
            msg.setPlayerId(dataEntry.getKey());
            msg.setLen(packet.getLen());
            AgentServerLinkControl.routeClient(msg);
        }
    }
}
